package com.mtw.bbs.common.web.config;

import com.mtw.bbs.common.core.security.AccessLimitService;
import com.mtw.bbs.common.web.interceptor.AccessLimitInterceptor;
import com.mtw.bbs.common.web.interceptor.AuthHandlerInterceptor;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

    @Resource
    private AccessLimitService accessLimitService;

    @Value("${spring.application.name}")
    private String applicationName;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录信息清除
        registry.addInterceptor(new AuthHandlerInterceptor()).addPathPatterns("/**");
        // 限流拦截
        registry.addInterceptor(new AccessLimitInterceptor(accessLimitService,applicationName)).addPathPatterns("/**");
    }

}